package com.h117121.fashionshop.core.dom;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.web.multipart.MultipartFile;

@SuppressWarnings("serial")
@Entity
@Table(name = "Product")
public class Product extends BaseDom {
	@Column(name = "Name", length = 250, unique = false, nullable = false)
	private String name;

	@ManyToOne
	@JoinColumn(name = "ProductType")
	private ProductType type;

	@Column(name = "ImagePath", nullable = false)
	private String imagePath;

	@Transient
	private MultipartFile image;

	@Column(name = "Description", length = 1000, nullable = true)
	private String description;

	@Column(name = "Quantity", nullable = false)
	private int quantity;

	@Column(name = "AmountSold", nullable = false)
	private int amountSold;

	@Column(name = "Price", nullable = false)
	private long price;

	@Column(name = "DateAdded", nullable = false)
	private Date dateAdded;

	@Column(name = "MadeIn", nullable = false)
	private String madeIn;

	@Column(name = "Views", nullable = false)
	private long views;

	@ManyToOne
	@JoinColumn(name = "Producer")
	private Producer producer;

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the imagePath
	 */
	public String getImagePath() {
		return imagePath;
	}

	/**
	 * @param imagePath
	 *            the imagePath to set
	 */
	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the quantity
	 */
	public int getQuantity() {
		return quantity;
	}

	/**
	 * @param quantity
	 *            the quantity to set
	 */
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	/**
	 * @return the amountSold
	 */
	public int getAmountSold() {
		return amountSold;
	}

	/**
	 * @param amountSold
	 *            the amountSold to set
	 */
	public void setAmountSold(int amountSold) {
		this.amountSold = amountSold;
	}

	/**
	 * @return the price
	 */
	public long getPrice() {
		return price;
	}

	/**
	 * @param price
	 *            the price to set
	 */
	public void setPrice(long price) {
		this.price = price;
	}

	/**
	 * @return the producer
	 */
	public Producer getProducer() {
		return producer;
	}

	/**
	 * @param producer
	 *            the producer to set
	 */
	public void setProducer(Producer producer) {
		this.producer = producer;
	}

	/**
	 * @return the type
	 */
	public ProductType getType() {
		return type;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(ProductType type) {
		this.type = type;
	}

	/**
	 * @return the dateAdded
	 */
	public Date getDateAdded() {
		return dateAdded;
	}

	/**
	 * @param dateAdded
	 *            the dateAdded to set
	 */
	public void setDateAdded(Date dateAdded) {
		this.dateAdded = dateAdded;
	}

	/**
	 * @return the views
	 */
	public long getViews() {
		return views;
	}

	/**
	 * @param views
	 *            the views to set
	 */
	public void setViews(long views) {
		this.views = views;
	}

	/**
	 * @return the madeIn
	 */
	public String getMadeIn() {
		return madeIn;
	}

	/**
	 * @param madeIn
	 *            the madeIn to set
	 */
	public void setMadeIn(String madeIn) {
		this.madeIn = madeIn;
	}

	public MultipartFile getImage() {
		return image;
	}

	public void setImage(MultipartFile image) {
		this.image = image;
	}

	@Override
	public String toString() {
		return "*** " + id + " - " + name + " - " + price + " - "
				+ producer.getName() + " - " + madeIn + " - " + dateAdded
				+ " - " + description + " ***";
	}

	public Product copy(Product product) {
		this.amountSold = product.amountSold;
		this.dateAdded = product.dateAdded;
		this.description = product.description;
		this.imagePath = product.imagePath;
		this.madeIn = product.madeIn;
		this.name = product.name;
		this.price = product.price;
		this.producer = product.producer;
		this.quantity = product.quantity;
		this.type = product.type;
		this.views = product.views;
		this.version = product.version;
		return this;
	}
}
